package com.maltys.config.security;

import com.maltys.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author malty
 */

public class BaseSecurityConfig {
    @Autowired
    private IUserService userService;

    @Bean
    public UserDetailsService userDetailsService() {
        return userName -> userService.getUserByUsername(userName);
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        // 使用 BCryptPasswordEncoder 加密密码
        return new BCryptPasswordEncoder();
    }
}
